/*!
 * @Author: CPS
 * @email: 373704015@qq.com
 * @Date: 2020-08-31 01:33:49
 * @Last Modified by: SSD_WIN10
 * @Last Modified time: 2020-09-22 21:42:15
 * @Projectname Electron-fileWatcher
 * @file_path "D:\CPS\IDE\3176x32 前端\Data\Packages\testt\Plugins\main.js"
 * @Filename "main.js"
 */
'use strict'
//初始化
process.stdin.resume()

//设置编码
process.stdin.setEncoding('utf8')

//获取传输过来的数据
let input = ''
process.stdin.on('data', function(data) {
  input += data
})

// 接收完成后,调用模块处理
process.stdin.on('end', function() {

  /* 验证配置文件格式是否json */
  let config = process.argv[3] //配置文件 JSON格式
  if (config) {
    try {
      config = JSON.parse(process.argv[3])
    } catch (e) {
      //返回错误 & 退出
      process.stdout.write('没有正确的配置文件' + e)
      process.exit()
    }
  }

  let res
  let target = process.argv[2].toLowerCase() //要处理的文件的格式

  switch (syntax) {
    /*载入stylus格式库*/
    case 'stylus':
      const stylusBeautify = require('./stylusBeautify/index.js')
      res = stylusBeautify(
        input,
        config
      )
      break;

      /*html to pug 的格式化*/
    case 'html2pug':
      const html2pug = require('./html2pug/index.js')
      res = html2pug(input)
      break;

      /*pug 的格式化*/
    case 'pug':
      const pugBeautify = require('./pugBeautify/index.js')
      res = vueBeautify(
        input,
        config
      )
      break;
  }

  process.stdout.write(res)
})
